﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UI.teacher
{
    public partial class Grade : Form
    {
        public int ET_Id = 0;
        public Grade()
        {
            InitializeComponent();
        }

        private void Grade_Load(object sender, EventArgs e)
        {
            if (ET_Id == 0)
            {
                MessageBox.Show("获取数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            GetData();
        }

        public void GetData()
        {
            JD();
            this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sid = this.comboBox1.SelectedValue.ToString();
            if (!sid.Equals("0"))
            {
                List<XueMeng.Model.Stage> s = new XueMeng.BLL.StageManager().GetModelList("S_Id=" + sid + "");
                this.textBox1.Text = s[0].S_Context;
            }
        }

        public void JD()
        {
            int count = new XueMeng.BLL.StageManager().GetRecordCount("ET_Id="+this.ET_Id+"");
            List<XueMeng.Model.Post> list = new List<XueMeng.Model.Post>();

            list.Insert(0, new XueMeng.Model.Post() { P_Id = 0, P_Name = "请选择" });
            if (count > 0)
            {
                List<XueMeng.Model.Stage> s = new XueMeng.BLL.StageManager().GetModelList("ET_Id=" + this.ET_Id + "");
                for (int i = 1; i <= s.Count; i++)
                {
                    list.Insert(i, new XueMeng.Model.Post() { P_Id = s[i-1].S_Id, P_Name = "阶段"+i+""});
                }
            }
            this.comboBox1.DataSource = list;
            this.comboBox1.DisplayMember = "P_Name";
            this.comboBox1.ValueMember = "P_Id";
            this.comboBox1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddGrade ag = new AddGrade();
            ag.ET_Id = this.ET_Id;
            ag.Owner = this;
            ag.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
